'use strict';

const {DataTypes} = require("sequelize");
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up (queryInterface, Sequelize) {
    /**
     * Add altering commands here.
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */
    await queryInterface.removeColumn("Comments", "repliedToUserId")
    await queryInterface.addColumn("Comments", "rootId", {
      type: DataTypes.INTEGER
    })
    await queryInterface.addColumn("Comments", "level", {
      type: DataTypes.INTEGER,
      defaultValue: 1,
      comment: "评论层级: 1=一级评论, 2=二级评论, 3=三级评论"
    })

    await queryInterface.addIndex("Comments", ["rootId"])
    await queryInterface.addIndex("Comments", ["level"])
    await queryInterface.addIndex("Comments", ["parentId"])
  },

  async down (queryInterface, Sequelize) {
    /**
     * Add reverting commands here.
     *
     * Example:
     * await queryInterface.dropTable('users');
     */
    await queryInterface.removeColumn("Comments", "rootId")
    await queryInterface.removeColumn("Comments", "level")
  }
};
